using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlackScreen : MonoBehaviour
{
    [SerializeField] private float colorDisapperanceSpeed;
    [SerializeField]private SpriteRenderer sr;
    [SerializeField]private bool isStart;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.GetComponent<Player>() != null)
        {
            isStart = true;
        }
    }

    private void Update()
    {
        if (isStart)
        {
            float alpha = sr.color.a - colorDisapperanceSpeed * Time.deltaTime;
            sr.color = new Color(sr.color.r, sr.color.g, sr .color.b, alpha);

            if (sr.color.a <= 0)
                isStart = false;
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.GetComponent<Player>() != null)
        {
            sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 1);
            isStart = false;
        }
    }

}
